<?php

	include("../mysql_connect.php");
	include("PHPMailer/class.phpmailer.php");
	include("../error/upload.php");

	$xml = simplexml_load_file('php://input');

	foreach( $xml->attributes( ) as $attr)
	{
		$AttrArray[] = $attr;
	}
	
	$UserName = $AttrArray[0];
	
	
	foreach( $xml->children() as $child)
	{
		switch ($child->getName())
		{
			case "SendEmail":
				foreach( $child->attributes( ) as $attr)
					$SendEmail[] = (string)$attr;
				break;
			case "MediaInfo":
				foreach( $child->attributes( ) as $attr)
					$MediaInfo[] = (string)$attr;
				break;
		}
	}
	
	foreach( $SendEmail as $Email) {
		
		
		$mail = new PHPMailer(); 				//New instance, with exceptions enabled		
		$mail->IsSMTP();                        // tell the class to use SMTP
		$mail->SMTPAuth   = true;               // enable SMTP authentication
			
		$mail->SMTPSecure = "ssl";
		$mail->Port       = 465;                // set the SMTP server port
		$mail->Host       = "smtp.gmail.com";   // SMTP server
		$mail->Username   = "info@bespoke-app.com";     // SMTP server username
		$mail->Password   = "gobespoke";                // SMTP server password
		
		$mail->From       = "info@bespoke-app.com";
		$mail->FromName   = "Bespoke";
		$mail->Subject  = "".$UserName." has shared an inspiration book with you.";
		$mail->AddAddress($Email);
		if (isset($MediaInfo))
			$mail->Body = "Hi ".$Email.",<p>I have shared my Inspiration Book on Bespoke with you.</p><p>".implode("<p>",$MediaInfo)."</p><p>Cheers,</p>".$UserName."";
		else
			$mail->Body = "Hi ".$Email.",<p>I have shared my Inspiration Book on Bespoke with you.</p><p>Cheers,</p>".$UserName."";
		$mail->IsHTML(true);      
		if(!$mail->Send()) {
			echo "<Error Message=\"". $mail->ErrorInfo."\" Domain=\"SendEmailInMyBook\"/>";
			SaveError("ForgotPassword", NULL, date("Y-m-d H:i:s"), $mail->ErrorInfo);
			return;
		}
	}
	echo "<Success Message=\"The requested Information was accepted\" Domain=\"Configuration\"/>"; 
			
	

?>
